package com.android.huimeiqupin.fragment.group;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.huimeiqupin.fragment.BaseLazyFragment;
import com.android.huimeiqupin.model.MainTabData;
import com.android.huimeiqupin.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/15.
 */

public class Fragment_EveryBodyBuy extends BaseLazyFragment {
    @BindView(R.id.tab_hot)
    TabLayout tabLayout;
    @BindView(R.id.pager_hot)
    ViewPager viewPager;
    @BindView(R.id.main_top_title)
    TextView mainTopTitle;
    @BindView(R.id.main_top_bg)
    Toolbar mainTopBg;
    private FragmentActivity mcontext;
    private ArrayList<MainTabData> names = new ArrayList<>();
    private View view;

    public static Fragment_EveryBodyBuy newInstance() {
        Fragment_EveryBodyBuy fragment = new Fragment_EveryBodyBuy();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_fragment2, container, false);
        mcontext = getActivity();
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initPrepare() {
        initUI();
    }

    @Override
    protected void onInvisible() {

    }

    @Override
    protected void initData() {
    }

    private void initUI() {
        mainTopBg.setVisibility(View.GONE);
        names.add(new MainTabData("大家都在买", "&order=sales&sort=DESC"));
        names.add(new MainTabData("最新", "&order=new&sort=DESC"));
        HotFragmentPagerAdapter pagerAdapter = new HotFragmentPagerAdapter(mcontext.getSupportFragmentManager());
        viewPager.setAdapter(pagerAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }


    private class HotFragmentPagerAdapter extends FragmentPagerAdapter {
        private HotFragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return Fragment_TabRecommendList.newInstance(names.get(position).getId());
        }

        @Override
        public int getCount() {
            return names.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return names.get(position).getName();
        }
    }
}
